#ifndef FTPUTIL_H
#define FTPUTIL_H

#include <QFtp>
#include <QSet>
#include <QStringList>
#include "bean.h"
#include <QFile>
#include <QHash>


class FtpUtil:public QObject
{
    Q_OBJECT
public:
    FtpUtil();
    void initConn(const QString &ip,const QString &username,const QString &password);
    bool connectFtp();
    bool closeFtp();
    bool upload(const FileBean &bean);
    bool upload(const QList<FileBean> &beanlist);
    bool mkdir(const QString &dir);
    bool mkdir(const QStringList &dirlist);
    bool rmdir(const QString &dir);
    bool rm(const QString &filename);
    bool rm(const QStringList &filelist);
    void cd(const QString &dir);
    void list();
    void upload(const QByteArray & data, const QString & file);
    bool isconnect();
    void download(const QString &filename);

signals:
    void updateStatus(LogType type,LogLevel level,const QString &msg);
    void updateRemoteView();
    void clearRemoteView();
    void addToRemote(const QUrlInfo &info);
    void updateRunstate();
    void setBoxInfo();


private:
    int retryCount;

    void getBoxInfo();
public:
    QFtp *ftp;
    QString ftpip,username,password;
    QHash<int, QString> logInfo;


public slots:
    void ftpCommandFinished(int commandId, bool error);
    void ftpCommandStarted(int);
    void ftpRawCommandReply( int replyCode, const QString & detail );
    void addToList(const QUrlInfo &info);
};

#endif // FTPUTIL_H
